// var API_URL = 'http://127.0.0.1:8080/trainings/ap/customer?enc=0'
// var UPLOAD_URL = 'http://127.0.0.1:8080/trainings/ap/upload/picture'
var API_URL = 'https://hxzwpt.cn/trainings/ap/customer?enc=0'
var UPLOAD_URL = 'https://hxzwpt.cn/trainings/ap/upload/picture'
var params = {
  "optid": "customer_register",
  "terminal": "1",
  "version": "1",
  "common_param": {
    "page_index": "",
    "page_size": "",
    "is_paging": "0",
    "is_couting": "0"
  },
  "business_param": {
  },
}
var requestHandler = {
  success: function (res) {
    // success  
  },
  fail: function () {
    // fail  
  },
}

//GET请求  
function GET(requestHandler) {
  request('GET', requestHandler)
}
//POST请求  
function POST(requestHandler) {
  request('POST', requestHandler)
}

function request(method, requestHandler) {
  //注意：可以对params加密等处理  
  var param = Object.assign({}, params, requestHandler.params);
  param.optid = requestHandler.url
  wx.request({
    url: API_URL,
    data: JSON.stringify(param),
    method: method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT  
    // header: {}, // 设置请求的 header  
    success: function (res) {
      //注意：可以对参数解密等处理
        if (res.data.result_state === '0') {
            requestHandler.success(res.data)
        } else {
            wx.showToast({
                title: res.data.result_msg,
                icon: 'none',
                duration: 2000
            })
            requestHandler.fail(res.data)
            // requestHandler.success(res.data)
        }
    },
    fail: function () {
      requestHandler.fail()
    },
    complete: function () {
      // complete  
    }
  })
}

module.exports = {
  GET: GET,
  POST: POST,
  UPLOAD_URL: UPLOAD_URL
}  